﻿<%@ Control Language="VB" AutoEventWireup="false" CodeFile="OpenManageRoleBrandMappingV3.ascx.vb" Inherits="WebForm_ManageRole_OpenManageRoleBrandMappingV3" %>
 <script language="javascript">
    //checkbox點擊事件
    function OnCheckEvent()
    {
        var objNode = event.srcElement;
        if(objNode.tagName != "INPUT" || objNode.type != "checkbox")
            {
                return;
            }
        //取得當前節點
        var ck_ID = objNode.getAttribute("ID");
        var node_ID = ck_ID.substring(0,ck_ID.indexOf("CheckBox")) + "Nodes";
        var curTreeNode = document.getElementById(node_ID);
        //連動選擇
        SetChildCheckBox(curTreeNode,objNode.checked);
        SetParentCheckBox(objNode);
    }
    
    //子節點字串
    var childIds = "";
    //取得子節點ID集合
    function GetChildIdArray(parentNode)
    {
        if (parentNode == null)
            {    
                return;
            }
        var childNodes = parentNode.children;
        var count = childNodes.length;
        for(var i = 0;i < count;i ++)
        {
            var tmpNode = childNodes[i];
            if(tmpNode.tagName == "INPUT" && tmpNode.type == "checkbox")
                {
                    childIds = tmpNode.id + ":" + childIds;
                }
            GetChildIdArray(tmpNode);
        }
    }
    
    //設置子節點的checkbox
    function SetChildCheckBox(parentNode,checked)
    {
        if(parentNode == null)
            {    
                return;
            }
        var childNodes = parentNode.children;
        var count = childNodes.length;
        for(var i = 0;i < count;i ++)
        {
            var tmpNode = childNodes[i];
            if(tmpNode.tagName == "INPUT" && tmpNode.type == "checkbox")
                {
                    tmpNode.checked = checked;
                }
            SetChildCheckBox(tmpNode,checked);
        }
    }
    
    //設置父節點的checkbox
    function SetParentCheckBox(childNode)
    {
        if(childNode == null)
            {
                return;
            }
        var parent = childNode.parentNode;
        if(parent == null || parent == "undefined")
            {
                return;
            }    
        do 
            {
                parent = parent.parentNode;
            }
        while (parent && parent.tagName != "DIV");
        if(parent == "undefined" || parent == null)
            {    
                return;
            }
        var parentId = parent.getAttribute("ID");
        var objParent = document.getElementById(parentId);
        childIds = "";
        GetChildIdArray(objParent);
        //判斷子節點狀態
        childIds = childIds.substring(0,childIds.length - 1);
        var aryChild = childIds.split(":");
        var result = false;
        //當子節點的checkbox狀態有一個為true，其父節點checkbox狀態即為true,否則為false
        for(var i in aryChild)
        {
            var childCk = document.getElementById(aryChild[i]);
            if(childCk.checked)
                {
                    result = true;
                }
        }
        parentId = parentId.replace("Nodes","CheckBox");
        var parentCk = document.getElementById(parentId);
        if(parentCk == null)
            {
                return;
            }
        if(result)
            {
                parentCk.checked = true;
            }
        else
            {
                parentCk.checked = false;
            }
        SetParentCheckBox(parentCk);
    }
    </script>

<asp:Panel ID="panel1" runat="server" HorizontalAlign="Center" BackColor="white" BorderWidth="1" Style="cursor: move;
    display: none" Width="650" Height="550" ScrollBars="Auto">
    <br />
      <fieldset align="left">
            <legend>
                    <asp:Label ID="lblTitle" runat="server" Text="<%$ Resources:Title %>" SkinID="title"></asp:Label>
            </legend>
        <table width="50%">
            <tr>
                <td align="left">
                    <asp:Label ID="lblViewPoint" runat="server" Text="<%$ Resources:ViewPoint %>"></asp:Label>
                    <asp:DropDownList ID="ddlViewPoint" runat="server"></asp:DropDownList>  
                    <asp:Button ID="btQuery" Text="Query"  ValidationGroup="vVPoint" runat="server"  />
                    <asp:RequiredFieldValidator ID="rfvViewPoint" runat="server" meta:resourcekey="rfvViewPoint" SetFocusOnError="true" ValidationGroup="vVPoint" ControlToValidate="ddlViewPoint" Display="None"></asp:RequiredFieldValidator>
                    <asp:ValidationSummary ID="vs3" ValidationGroup="vVPoint" runat="server" ShowMessageBox="true" ShowSummary="false"  />
                </td>
          </tr>
    <tr>
    <td>
      <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
             <ContentTemplate>
                <asp:TreeView ID="tvHierarchy" runat="server"   ImageSet="Simple" ShowLines="true" Visible="false" ShowCheckBoxes="All" OnTreeNodeCheckChanged="tvHierarchy_TreeNodeCheckChanged">
                    <Nodes>
                        <asp:TreeNode Text="Root">
                            <asp:TreeNode Text="D1">
                                <asp:TreeNode Text="D3">
                                </asp:TreeNode>
                            </asp:TreeNode>
                            <asp:TreeNode Text="D2">
                            </asp:TreeNode>
                       </asp:TreeNode>
                   </Nodes>
                </asp:TreeView>
               </ContentTemplate>
        </asp:UpdatePanel>
          
    </td>
    </tr>
    <tr>
            <td align="center">
                <asp:Button ID="btnOK" Visible="false" runat="server" Text="<%$ Resources:OK %>" />
                <asp:Button ID="btnApply" runat="server" Text="<%$ Resources:Apply %>" />
                <asp:Button ID="btnCancel" runat="server" Text="<%$ Resources:Cancel %>" />
            </td>
        </tr>
        </table> 
      </fieldset>
</asp:Panel>

<asp:Button ID="btnDummy" runat="server" SkinID="null" Style="display: none" />
<ajaxToolkit:ModalPopupExtender ID="mpSearch" runat="server"  CancelControlID="btnCancel"
    PopupControlID="panel1" PopupDragHandleControlID="panel1" TargetControlID="btnDummy" />
